package com.jindy.module.approval.service.impl;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.DateUtils;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.approval.domain.Approval;
import com.jindy.module.approval.mapper.ApprovalMapper;
import com.jindy.module.approval.service.ApprovalService;
import com.jindy.system.service.ISysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 审批Service业务实现类
 *
 * @author 朝夕
 * @date 2022-12-28
 */
@Service
public class ApprovalServiceImpl implements ApprovalService {

    @Resource
    private ApprovalMapper approvalMapper;

    @Resource
    private ISysUserService sysUserService;

    /**
     * 查询审批列表
     *
     * @param approval 报备
     * @return 报备列表
     */
    @Override
    public List<Approval> selectApprovalList(Approval approval) {
        return approvalMapper.selectApprovalList(approval);
    }

    /**
     * 查询审批
     *
     * @param id 审批主键
     * @return 审批数据
     */
    @Override
    public Approval selectApprovalById(String id) {
        return approvalMapper.selectApprovalById(id);
    }


    /**
     * 新增审批数据
     *
     * @param approval 审批
     * @return 结果
     */
    @Override
    public int insertApproval(Approval approval)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        approval.setCreateBy(sysUser.getUserName());
        approval.setCreateTime(DateUtils.getNowDate());
        return approvalMapper.insertApproval(approval);
    }

    /**
     * 修改审批数据
     *
     * @param approval
     * @return 结果
     */
    @Override
    public int updateApproval(Approval approval) {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        approval.setUpdateBy(sysUser.getUserName());
        approval.setUpdateTime(DateUtils.getNowDate());
        return approvalMapper.updateApproval(approval);
    }

    /**
     * 删除审批数据
     *
     * @param id 审批主键
     * @return 结果
     */
    @Override
    public int deleteApprovalById(String id)
    {
        return approvalMapper.deleteApprovalById(id);
    }

    /**
     * 批量删除
     *
     * @param ids 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteApprovalByIds(String[] ids)
    {
        return approvalMapper.deleteApprovalByIds(ids);
    }
}
